package com.zyh.contract.controller;

import com.zyh.common.annotation.Log;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.common.core.page.TableDataInfo;
import com.zyh.common.enums.BusinessType;
import com.zyh.common.utils.poi.ExcelUtil;
import com.zyh.contract.domain.RentalContract;
import com.zyh.contract.service.IRentalContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租赁管理Controller
 * 
 * @author zyh
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/contract/contract")
public class RentalContractController extends BaseController
{
    @Autowired
    private IRentalContractService rentalContractService;

    /**
     * 查询租赁管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalContract rentalContract)
    {
        startPage();
        List<RentalContract> list = rentalContractService.selectRentalContractList(rentalContract);
        return getDataTable(list);
    }

    /**
     * 导出租赁管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:export')")
    @Log(title = "租赁管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalContract rentalContract)
    {
        List<RentalContract> list = rentalContractService.selectRentalContractList(rentalContract);
        ExcelUtil<RentalContract> util = new ExcelUtil<RentalContract>(RentalContract.class);
        util.exportExcel(response, list, "租赁管理数据");
    }

    /**
     * 获取租赁管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rentalContractService.selectRentalContractById(id));
    }

    /**
     * 新增租赁管理
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:add')")
    @Log(title = "租赁管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalContract rentalContract)
    {
        return toAjax(rentalContractService.insertRentalContract(rentalContract));
    }

    /**
     * 修改租赁管理
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:edit')")
    @Log(title = "租赁管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalContract rentalContract)
    {
        return toAjax(rentalContractService.updateRentalContract(rentalContract));
    }

    /**
     * 删除租赁管理
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:remove')")
    @Log(title = "租赁管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rentalContractService.deleteRentalContractByIds(ids));
    }
}
